package com.wn.pettyloan.security.emp;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.wn.pettyloan.util.Result;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: pettyloan
 * @ClassName EmpLoginAuthenticationFailureHandler
 * @description:
 * @author: 韩旭
 * @create: 2022-12-15 14:27
 **/
public class EmpLoginAuthenticationFailureHandler  extends SimpleUrlAuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        response.setContentType("application/json;charset=UTF-8");
        String string = new ObjectMapper().writeValueAsString(Result.error("请检查用户名、密码是否正确"));
        response.getWriter().println(string);
    }

}